#include <iostream>
#include <math.h>
using namespace std;


int main()
{
	int S1[] = { -1,0,9 };
	int S2[] = { -25,-10,10,11 };
	int S3[] = { 2,9,17,30,40 };

	int n1 = sizeof(S1) / sizeof(int);
	int n2 = sizeof(S2) / sizeof(int);
	int n3 = sizeof(S3) / sizeof(int);

	int minnum = INT_MAX;
	for (int i = 0; i < n1; i++)
	{
		for (int j = 0; j < n2; j++)
		{
			for (int k = 0; k < n3; k++)
			{
				int D = abs(S1[i] - S2[j]) + abs(S2[j] - S3[k]) + abs(S3[k] - S1[i]);
				minnum = min(D, minnum);
			}
		}
	}
	cout << minnum << endl;
	return 0;
}